#include<bits/stdc++.h>
#define N 1000005
//#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SIZE,stdin),(iS==iT?EOF:*iS++)):*iS++)
#define gc() getchar()
#define fi first
#define se second
#define Kamisato return
#define Ayaka 0;
#define file(_s) freopen(#_s".in","r",stdin);freopen(#_s".out","w",stdout);
//#define CHECK_MEMORY ___JQH___
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9;
const ll INF=2e18;
bool Memory_Begin;
namespace IO{const int SIZE=(1<<21)+1;char ibuf[SIZE],*iS,*iT,obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1,c,qu[55];int f,qr;inline void flush(){fwrite(obuf,1,oS-obuf,stdout),oS=obuf,fflush(stdout);}inline void putc(char x){*oS++=x;if(oS==oT)flush();}template <class I>inline void read(I &x){for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;}template <class I>inline void print(I x){if(!x)putc('0');if(x<0)putc('-'),x=-x;while(x)qu[++qr]=x%10+'0',x/=10;while(qr)putc(qu[qr --]);}inline void reads(string &s){s.clear();for(c=gc();c<33||c>126;)c=gc();for(;c>=33&&c<=126;c=gc())s.push_back(c);}inline void prints(string s){for(char c:s)putc(c);}struct Flusher_ {~Flusher_(){flush();}}io_flusher_;}
using IO::read;using IO::putc;using IO::print;using IO::reads;using IO::prints;
template<class I>I updiv(I x,I y){return (x%y==0?x/y:x/y+1);}
template<class I>bool cmin(I &x,I y){if(x>y)return x=y,1;return 0;}
template<class I>bool cmax(I &x,I y){if(x<y)return x=y,1;return 0;}

int n;
ll B[N],C;
vector<int>a[N];
int tot,dsc[N],buc[N];
bool Memory_End;
signed main()
{
#ifdef CHECK_MEMORY
	cerr<<"Memory: "<<(&Memory_End-&Memory_Begin)/1048576.0<<" MiB\n";
#endif
	file(list);
	read(n);
	for(int i=1,k,x;i<=n;i++)
	{
		read(k);
		while(k--)
		{
			read(x);
			a[i].push_back(x);
			dsc[++tot]=x;
		}
	}
	sort(dsc+1,dsc+tot+1);
	tot=unique(dsc+1,dsc+tot+1)-dsc-1;
	read(C);
	for(int i=1;i<=n;i++) read(B[i]),B[i]*=i;
	ll ans=INF,sum=0;
	priority_queue<pii,vector<pii>,greater<pii> >q;
	ll cnt=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<(int)a[i].size();j++)
		{
			int p=lower_bound(dsc+1,dsc+tot+1,a[i][j])-dsc;
			if(j) q.push({a[i][j]-a[i][j-1]+1,p});
			buc[p]++,cnt++;
			sum+=B[buc[p]]-B[buc[p]-1];
			sum+=C;
		}
	}
	vector<int>v;
	ans=sum,v.push_back(1);
	int las=1;
	while(q.size())
	{
		int x=q.top().fi;
		sum+=cnt*(x-las)*C;
		las=x;
		while(q.size()&&q.top().fi==x)
		{
			int p=q.top().se;
			q.pop();
			buc[p]--,cnt--;
			sum+=B[buc[p]]-B[buc[p]+1];
			sum-=C;
		}
		if(cmin(ans,sum)) v.clear();
		if(sum==ans) v.push_back(x);
	}
	print(ans),putc(' ');
	print(v.size()),putc('\n');
	for(int x:v) print(x),putc(' ');
	Kamisato Ayaka
}
